<template>
  <div class="list-item" @click="onDetail">
    <div class="i-top">
      <span class="color-black flex">
        <div class="round"><img src="@/assets/images/store.png" /></div>
        <span class="overLine">{{ itemData.marketName }}</span>
      </span>
      <span class="right overLine" :class="[itemData.maintenanceStage === 'A' ? 'color-org' : 'color-normal']">
        {{ getDictName('CTM_MARKET_BUID_WEEK_MAINTENANCE_PROGRESS', itemData.maintenanceStage) }}
        <!-- 市场建设周任务维护进度 A/D 属于待跟进 -->
      </span>
    </div>
    <div class="address">
      <img src="@/assets/images/position.png" />
      <div>
        {{ itemData.provinceName }}{{ itemData.cityName }}{{ itemData.districtName }}{{ itemData.streetName }}
        <!-- {{ itemData.address }} -->
      </div>
    </div>
    <div class="content">
      <div>
        任务日期：<span class="color-black">{{ parseTime(itemData.createTime, '{y}年{m}月') }}</span>
      </div>
      <div>
        周数：<span class="color-black">{{ itemData.weekNumber || '--' }}</span>
      </div>
      <div>
        市场类型：<span class="color-black">{{ getDictName('TOBE_MARKET_TYPE', itemData.marketType) }}</span>
      </div>
      <div>
        进展程度：
        <span class="color-black">
          {{ getDictName('CTM_MARKET_BUID_FOLLOW_UP_PROGRESS', itemData.progressStage) }}
        </span>
      </div>
    </div>
    <div class="btns" v-if="itemData.maintenanceStage === 'A' || itemData.maintenanceStage === 'D'">
      <div class="btn radius-larg ctm-btn-grey-outline" @click.stop="onFollowUp">进度提报</div>
    </div>
  </div>
</template>

<script lang="ts">
  import { defineComponent } from 'vue'
  import { parseTime } from '@/utils'

  export default defineComponent({
    name: 'StoreUpgraderItem',
    props: {
      itemData: {
        type: Object,
        default: () => {}
      },
      dictData: {
        type: Object,
        default: () => {}
      }
    },
    setup(props, { emit }) {
      const onFollowUp = () => {
        emit('followUp')
      }

      const onDetail = () => {
        emit('detail')
      }

      const getDictName = (dictType: string, code: any) => {
        if (!dictType || [undefined, null, ''].includes(code)) return '--'
        let name = code
        const dictList = props.dictData[dictType] || []
        if (dictList.length > 0) {
          const obj = dictList.find((v: any) => v.dictCode === `${code}`)
          name = obj?.dictName || code
        }
        return name
      }

      return {
        onFollowUp,
        onDetail,
        getDictName,
        parseTime
      }
    }
  })
</script>
<style lang="less" scoped>
  .list-item {
    margin-bottom: 8px;
    padding: 16px;
    background: var(--bg-global-weaker);
    border-radius: 8px;
    font: var(--font-main-body);
    color: var(--texticon-default-stronger);

    .i-top {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 24px;
      font: var(--font-main-title-strengthen);

      .flex {
        display: flex;
        align-items: center;
        margin-right: 10px;

        span {
          max-width: 200px;
        }
      }

      .round {
        width: 24px;
        height: 24px;
        background: var(--texticon-color-warning-normal);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 4px;

        img {
          width: 16px;
          height: 16px;
        }
      }

      .right {
        // color: var(--texticon-color-secondary-normal);
        font: var(--font-main-body);
      }
    }

    .address {
      display: flex;
      align-items: center;
      margin-top: 4px;
      min-height: 20px;
      img {
        width: 20px;
        height: 20px;
        margin-right: 6px;
      }
    }
    .content {
      margin-top: 8px;

      div {
        padding: 2px 0;
        display: flex;
        justify-content: space-between;

        font: var(--font-main-body);
        color: var(--texticon-default-stronger);
        line-height: 20px;
      }
    }

    .btns {
      display: flex;
      justify-content: flex-end;
      margin-top: 16px;

      .btn {
        width: 88px;
        height: 36px;
        margin-left: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
  }
</style>
